<!DOCTYPE HTML>
<html lang="zh-CN">

<head>
    <title>注册</title>
    <meta charset="UTF-8">
    <meta name="viewport" content=" initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <script src="https://og6593g2z.qnssl.com/fundebug.0.3.3.min.js" apikey="e65b1e28cd641345cd31ef6dce8ac62f7aaa3ba3420be5a1c4aa23ee3636992d"></script>
    <link href="{$Think.config.RESOURCEURL}wx_assets/css/common.css{$Think.config.RESOURCE_VER}" rel="stylesheet">
    <link href="{$Think.config.RESOURCEURL}wx_assets/personCenter/css/index.css{$Think.config.RESOURCE_VER}" rel="stylesheet">
    <link href="{$Think.config.RESOURCEURL}wx_assets/iconfont/iconfont.css{$Think.config.RESOURCE_VER}" rel="stylesheet">
    <script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.1.1.3.min.js{$Think.config.RESOURCE_VER}"></script>
    <script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.alert.js{$Think.config.RESOURCE_VER}"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/wx_share.js{$Think.config.RESOURCE_VER}"></script>
    <script src="{$Think.config.RESOURCEURL}wx_assets/js/util.js{$Think.config.RESOURCE_VER}" type="text/javascript"></script>
    <script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/product/cookie.js{$Think.config.RESOURCE_VER}"></script>
</head>

<body id="login">
      <div class="form fast-login" style="display: block;">
          <ul>
              <li>
                  <div>
                    <i class="iconfont">&#xe72c;</i>
                    <input type="text" placeholder="请输入姓名" class="name"/>
                  </div>
              </li>
              <li>
                <div>
                  <i class="iconfont">&#xe627;</i>
                  <input type="number" placeholder="请输入手机号" class="phone"/>
                </div>
              </li>
              <li>
                 <div>
                      <i class="iconfont">&#xe64a;</i>
                      <input type="number" placeholder="请输入验证码" class="code"/>
                      <span class="sms-btn">获取验证码</span>
                 </div>
              </li>
              <li>
                <div>
                  <i class="iconfont">&#xe6b2;</i>
                  <input type="password" placeholder="请设置密码" class="password js-password"/>
                </div>
              </li>
              <li>
                <div>
                  <i class="iconfont">&#xe6b2;</i>
                  <input type="password" placeholder="请确认密码" class="password js-confirm-password"/>
                </div>
              </li>
          </ul>
          <div class="login-btn register-btn">注册</div>
      </div>
      <div class="link-feild">
          <a href="{$Think.config.SERVER_HOST}call.html?customerId={$customerId}&module=personCenter&method=login">登录</a>
      </div>
</body>
<script>
    function Page() {};

    $.extend(Page.prototype, {
        init: function () {
            this.bindEvents();
            console.log($.util.getUa())
        },

        // 绑定事件
        bindEvents: function() {
          $('.sms-btn').click($.proxy(this.handleSendSmsBtnClick, this));
          $('.register-btn').click($.proxy(this.handleRegisterBtnClick, this));
        },

        // 点击发送验证码按钮
        handleSendSmsBtnClick: function() {
          if ($('.sms-btn').hasClass('disabled')) return;
          var phone = $('.fast-login .phone').val();
          if (!phone) {
            $.util.alert("请输入手机号码！");
            return false;
          }
          if(!(/^1[34578]\d{9}$/.test(phone))){
            $.util.alert("手机号码有误，请重填");
            return false;
          }
          var params = {
            phone: phone,
            type: 1
          }
          $.ajax({
              type: "get",
              url: '{$Think.config.SERVER_HOST}call.json?customerId={$customerId}',
              dataType: 'json',
              data: {
                module: 'personCenter',
                method: 'verifyPhone',
                params: JSON.stringify(params)
              },
              success: $.proxy(this.handleGteSmsSucc, this)
          });
        },

        // 获取短信成功后执行
        handleGteSmsSucc: function(res) {
          if (+res.code === 0) {
            $('.sms-btn').addClass('disabled');
            var second = 60;
            $('.sms-btn').text('60s后重新获取')
            var timer = setInterval(function(){
              $('.sms-btn').text(--second + 's后重新获取')
              if (second <= 0) {
                clearInterval(timer);
                $('.sms-btn').removeClass('disabled');
                $('.sms-btn').text('获取验证码');
              }
            }, 1000)
          } else {
            $.util.alert(res.msg);
          }
        },

        // 点击注册按钮
        handleRegisterBtnClick: function() {
          var name = $('.name').val();
          var phone = $('.phone').val();
          var code = $('.code').val();
          var password = $('.js-password').val();
          var confirmPassword = $('.js-confirm-password').val();
          if (!name) {
            $.util.alert("请输入姓名！");
            return false;
          }
          if (!phone) {
            $.util.alert("请输入手机号码！");
            return false;
          }
          if(!(/^1[34578]\d{9}$/.test(phone))){
            $.util.alert("手机号码有误，请重填");
            return false;
          }
          if (!code) {
            $.util.alert("请输入验证码！");
            return false;
          }
          if (!password) {
            $.util.alert("请输入密码！");
            return false;
          }
          if (password !== confirmPassword) {
            $.util.alert("两次输入的密码不一致，请重新输入！");
            return false;
          }
          var params = {
            name: name,
            phone: phone,
            code: code,
            password: password
          }
          $.ajax({
              type: "get",
              url: '{$Think.config.SERVER_HOST}call.json?customerId={$customerId}',
              dataType: 'json',
              data: {
                module: 'personCenter',
                method: 'register',
                params: JSON.stringify(params)
              },
              success: $.proxy(this.handleRegisterSucc, this)
          });
        },

        // 注册成功后执行
        handleRegisterSucc: function(res) {
          if (+res.code === 0) {
            location.href = '{$Think.config.SERVER_HOST}call.html?customerId={$customerId}&module=personCenter&method=index'
          } else {
            $.util.alert(res.msg)
          }
        }
    });

    var page = new Page();
    page.init();
</script>
</html>
